#include "arene.h"
#include <stdio.h>


void areneInit(Arene *pArene)
{
    int x,y;

    const char arene_defaut[15][20] =
    {

        /*"####################",
        "#..................#",
        "#..................#",
        "#..................#",
        "#............*.....#",
        "....................",
        "....................",
        "#..................#",
        "#..................#",
        "#..................#",
        "#..................#",
        "#..................#",
        "#..................#",
        "#..................#",
        "####################"*/

        "....................",
        "....................",
        "........*...........",
        "....................",
        "....................",
        "....................",
        "....................",
        "....................",
        "....................",
        "....................",
        "....................",
        "....................",
        "....................",
        "....................",
        "....................",

    };


    pArene->dimX = 20;
    pArene->dimY = 15;

    pArene->tab = (char **)malloc(sizeof(char *)*pArene->dimY);
    for (y=0; y<pArene->dimY; y++)
        pArene->tab[y] = (char *)malloc(sizeof(char)*pArene->dimX);

    for(y=0; y<pArene->dimY; ++y)
        for(x=0; x<pArene->dimX; ++x)
            pArene->tab[y][x] = arene_defaut[y][x];
}

int testPositionPerso(const Arene *pArene, int x, int y)
{
    return (/*x>=0 && x<pArene->dimX && y>=0 && y<pArene->dimY &&*/ pArene->tab[y][x] != '#');
}

const char areneGetXY(const Arene *pArene, const int x, const int y)
{
    return pArene->tab[y][x];
}
void areneSetXY(Arene *pArene, const int x, const int y, const char val)
{
    pArene->tab[y][x] = val;
}
const int getDimX(const Arene *pArene)
{
    return pArene->dimX;
}
const int getDimY(const Arene *pArene)
{
    return pArene->dimY;
}

void areneLibere(Arene *pArene)
{
    int y;

    for (y=0; y<pArene->dimY; y++)
        free(pArene->tab[y]);
    free(pArene->tab);

    pArene->dimX = 0;
    pArene->dimY = 0;
    pArene->tab = NULL;
}

int testPositionPills(const Arene*pArene,int x,int y)
{
    return(pArene->tab[y][x]=='*');
}
